package dxn.nl.file.api.export;

import com.alibaba.fastjson2.JSONObject;
import dxn.nl.file.client.core.CsExportDealServer;
import dxn.nl.file.client.core.DealExportService;
import dxn.nl.file.client.core.SteamQueryCallBackService;
import dxn.nl.file.client.model.dto.*;
import dxn.nl.file.client.model.enums.ExportDealResultTypeEnum;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Component
@CsExportDealServer(value = {"demo_export_stream_has_title"})
public class DealStreamExportHasTitle implements DealExportService {
    @Override
    public CsExportDealTypeHeadDto getExcelHeads(TransferMessageConfig config, TransferMessageData messageData, byte[] data) {
        List<CsExportExcelHeadDto> dtoList = Arrays.asList(new CsExportExcelHeadDto("a","name",1));
        CsExportDealTypeHeadDto dto = CsExportDealTypeHeadDto.streamDeal(dtoList);
        return dto;
    }

    @Override
    public String streamQueryData(TransferMessageConfig config, TransferMessageData messageData, byte[] data, SteamQueryCallBackService steamQueryCallBackService){

        List<JSONObject> list = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("a","name");
        list.add(jsonObject);

        // 流式导出，回调时必须指定sheet名称
        steamQueryCallBackService.handleResult(CsExportDealTypeHeadDto.defaultSheetName,list);
        return null;
    }
}
